package cc.yaomm.service.basic;

import cc.yaomm.common.basic.base.SuperApplication;
import cc.yaomm.common.basic.util.TokenUtils;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.beans.factory.config.EmbeddedValueResolver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.core.StringRedisTemplate;
import springfox.documentation.oas.annotations.EnableOpenApi;

/**
 * Created by XQL on 2021/6/15.
 */
@EnableOpenApi
@EnableDiscoveryClient
@SpringBootApplication
public class BasicServiceApp extends SuperApplication {

    public static void main(String[] args) {
        SpringApplication.run(BasicServiceApp.class, args);
    }

    @Bean
    public TokenUtils getTokenUtils(@Autowired StringRedisTemplate redisTemplate) {
        return new TokenUtils(2 * 60 * 60, redisTemplate);
    }

    /**
     * <p>@Description : EL表达式解析器 </p>
     * <p>@Author : QiLin.Xing </p>
     * <p>@Date : 2021/6/21 13:36 </p>
     */
    @Bean
    public EmbeddedValueResolver getEmbeddedValueResolver(@Autowired ConfigurableBeanFactory configurableBeanFactory) {
        return new EmbeddedValueResolver(configurableBeanFactory);
    }

    /**
     * <p>@Description : mybatis plus插件注入 </p>
     * <p>@Author : QiLin.Xing </p>
     * <p>@Date : 2021/6/21 13:36 </p>
     */
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor()); //乐观锁插件
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL)); //分页插件
        return interceptor;
    }

}
